home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / GoodBye / JohnKennedy / February96.lha / MASTERCLASS / KILLER.REXX next >
Encoding:
OS/2 REXX Batch file  |  1995-12-04  |  2.1 KB  |  118 lines

  1.  
  2. /* 
  3.     Search for file names
  4.     ending in #?bak, and then
  5.     delete them if necessary.
  6.          © John Kennedy
  7. */
  8.  
  9. address command /* Use AmigaDOS */
  10.  
  11. /* First, generate list of files & sizes */
  12.  
  13. Say "Making list of all files in current directory...."
  14.  
  15. 'list lformat "%p%n %l" all files > t:templist'
  16.  
  17.  
  18. /* Now, search for those ending in .bak */
  19.  
  20. Say "Adding up file sizes.."
  21.  
  22. infile='infile'
  23. outfile='outfile'
  24.  
  25. total_size=0
  26. number=0
  27.  
  28. call open(outfile,'t:report','w')
  29. call open(infile,"t:templist",'r')
  30.  
  31. do while ~eof(infile)
  32.     data=readln(infile)
  33.     if data~=''  then do
  34.         parse var data namepath " " size
  35.         if size='empty' then size=0
  36.         test=right(namepath,4)
  37.         if (test='.bak') then do
  38.             total_size=total_size+size
  39.             number=number+1
  40.             call writeln(outfile,namepath)
  41.         end
  42.     end
  43. end
  44. call close(infile)
  45. call close(outfile)
  46.  
  47. /* Process the files if required */
  48.  
  49. say "Number of backup files:" number
  50. say "Drive space taken up:  " total_size
  51. say
  52.  
  53. if number~=0 then call ProcessFiles()
  54.  
  55. /* All done! */
  56.  
  57. 'delete "t:report" quiet'
  58. 'delete "t:templist" quiet'
  59.  
  60. say "Finished."
  61. exit
  62.  
  63.  
  64.  
  65.  
  66. ProcessFiles:
  67.  
  68.     answer=''
  69.     do while (answer~="D" & answer~="C")
  70.         say "[D]elete files or [C]ancel?"
  71.         parse pull answer
  72.         answer=upper(answer)
  73.     end
  74.  
  75.     select
  76.         when answer='D' then call DeleteFiles()
  77.         when answer='C' then return
  78.     end
  79.  
  80.     return
  81.  
  82.  
  83. DeleteFiles:
  84.     
  85.     answer=''
  86.     confirm='Y'
  87.     do while (answer~="A" & answer~="C")
  88.         say "Delete [A]ll or [C]onfirm each one?"
  89.         parse pull answer
  90.         answer=upper(answer)
  91.     end
  92.  
  93.     call open(infile,"t:report",'r')
  94.     do n=1 to number
  95.         file=readln(infile)
  96.         data='delete '||d2c(34)||file||d2c(34)
  97.  
  98.  
  99.         if (answer="C") then 
  100.         do
  101.             confirm=''
  102.             do while (confirm~="Y" & confirm~="N" & confirm~="Q")
  103.             say "Delete " || file || " [Y]es, [N]o, [Q]uit?"
  104.             parse pull confirm
  105.             confirm=upper(confirm)
  106.             end
  107.         end
  108.         
  109.         if (confirm="Y") then interpret(data)
  110.         if (confirm="Q") then leave
  111.  
  112.     end
  113.     call close(infile)
  114.     return
  115.  
  116.  
  117.  
  118.